package com.xhj.xmly.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.xhj.xmly.R;
import com.xhj.xmly.adapter.RecommendIconAdapter;
import com.xhj.xmly.bean.SmallIcon;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class RecommendViewPagerBaseFragment extends Fragment {


    private RecyclerView recyclerview;
    private RecommendIconAdapter adapter;
    private List<SmallIcon> list;

    public RecommendViewPagerBaseFragment() {
        // Required empty public constructor
    }

    public static RecommendViewPagerBaseFragment newInstance(List<SmallIcon> iconlist) {

        Bundle args = new Bundle();
        args.putParcelableArrayList("iconlist",(ArrayList)iconlist);
        RecommendViewPagerBaseFragment fragment = new RecommendViewPagerBaseFragment();
        fragment.setArguments(args);
        Log.d("1600","newInstance");
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_recommend_view_pager_base,container,false);

        recyclerview = (RecyclerView) view.findViewById(R.id.recommend_icon_recycler);
        recyclerview.setLayoutManager(new GridLayoutManager(getContext(),4));
        list = new ArrayList<>();
        adapter = new RecommendIconAdapter(getContext(),list);
        recyclerview.setAdapter(adapter);
        Bundle bundle = getArguments();
        ArrayList<SmallIcon> iconlist = (ArrayList) bundle.getParcelableArrayList("iconlist");
        adapter.addAll(iconlist);

        return view;
    }





}
